﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Diagnostics;

namespace Smart.Common
{
    public partial class xucBaseB : xucBase
    {
        private bool m_Simple;
        public xucBaseB()
        {
            InitializeComponent();
            this.Init();
        }
        public virtual void Add()
        {
        }

        public virtual void Cancel()
        {
            base.Status = Actions.None;
            Cursor.Current = Cursors.Default;
            this.DisableControl(false);
            base.NotSave = false;
        }

        public virtual bool Check()
        {
            return true;
        }

        public virtual void Copy()
        {
        }

        public virtual void CustomerSelected(object item)
        {
        }

        public virtual void DeleteAll()
        {
        }

        public virtual void DeleteSelected()
        {
        }

        public virtual void DisableControl(bool disable)
        {
        }

        public void DisableMenu(bool disable)
        {
            this.Bar.Bar.bbiDeleteAll.Enabled = !disable;
            this.Bar.Bar.bbiDelete.Enabled = !disable;
            this.Bar.Bar.bbiSelectAll.Enabled = !disable;
            this.Bar.Bar.bbiProduct.Enabled = !disable;
            this.Bar.Bar.bbiSaveTemp.Enabled = !disable;
            this.Bar.Bar.bbiSaveToFile.Enabled = !disable;
        }


        protected virtual void EscapeExecute()
        {
        }

        protected virtual void F10Execute()
        {
        }

        protected virtual void F11Execute()
        {
        }

        protected virtual void F12Execute()
        {
        }

        protected virtual void F1Execute()
        {
        }

        protected virtual void F2Execute()
        {
        }

        protected virtual void F3Execute()
        {
        }

        protected virtual void F4Execute()
        {
        }

        protected virtual void F5Execute()
        {
        }

        protected virtual void F6Execute()
        {
        }

        protected virtual void F7Execute()
        {
        }

        protected virtual void F8Execute()
        {
        }

        protected virtual void F9Execute()
        {
        }

        protected virtual void Help()
        {
        }

        public virtual void History()
        {
        }

        public virtual void Init()
        {
            this.ucBarB.AddClick += new ButtonClickEventHander(this.ucToolBar_AddClick);
            this.ucBarB.SaveClick += new ButtonClickEventHander(this.ucToolBar_SaveClick);
            this.ucBarB.SaveNewClick += new ButtonClickEventHander(this.ucToolBar_SaveNewClick);
            this.ucBarB.CancleClick += new ButtonClickEventHander(this.ucToolBar_CancleClick);
            this.ucBarB.PrintClick += new ButtonClickEventHander(this.ucToolBar_PrintClick);
            this.ucBarB.CloseClick += new ButtonClickEventHander(this.ucToolBar_CloseClick);
            this.ucBarB.DeleteClick += new ButtonClickEventHander(this.ucToolBar_DeleteClick);
            this.ucBarB.ClearClick += new ButtonClickEventHander(this.ucToolBar_ClearClick);
            this.ucBarB.ProductDetailClick += new ButtonClickEventHander(this.ucToolBar_ProductDetailClick);
            this.ucBarB.HistoryClick += new ButtonClickEventHander(this.ucToolBar_HistoryClick);
            this.ucBarB.SearchClick += new ButtonClickEventHander(this.ucToolBar_SearchClick);
            this.ucBarB.InventoryClick += new ButtonClickEventHander(this.ucToolBar_InventoryClick);
            this.ucBarB.SaveDataTempClick += new ButtonClickEventHander(this.ucToolBar_SaveTempClick);
            this.ucBarB.RestoreDataTempClick += new ButtonClickEventHander(this.ucToolBar_RestoreTempClick);
            this.ucBarB.SaveDataToFileClick += new ButtonClickEventHander(this.ucToolBar_SaveToFileClick);
            this.ucBarB.ReadDataFromFileClick += new ButtonClickEventHander(this.ucToolBar_ReadFromFileClick);
            this.ucBarB.SelectAllClick += new ButtonClickEventHander(this.ucToolBar_SelectAllClick);
            this.ucBarB.ExportClick += new ButtonClickEventHander(this.ucToolBar_ExportClick);
            this.ucBarB.SaveDataByIdClick += new ButtonClickEventHander(this.ucToolBar_SaveDataByIDClick);
            this.ucBarB.ReadDataByIdClick += new ButtonClickEventHander(this.ucToolBar_ReadDataByIDClick);
            this.ucBarB.CopyClick += new ButtonClickEventHander(this.ucBarB_CopyClick);
            this.ucBarB.SaveLayoutClick += new ButtonClickEventHander(this.ucBarB_SaveLayoutClick);
            this.ucBarB.ReadLayoutClick += new ButtonClickEventHander(this.ucBarB_ReadLayoutClick);
            this.ucBarB.RefreshClick += new ButtonClickEventHander(this.ucBarB_RefreshClick);
            this.ucBarB.HelpClick += new ButtonClickEventHander(this.ucBarB_HelpClick);
        }

        public virtual void Inventory()
        {
        }

        public virtual void MakerInterface()
        {
        }

        public virtual void Mirror(string id)
        {
        }

        public virtual void Print()
        {
        }

        protected override bool ProcessDialogKey(Keys keyData)
        {
            switch (keyData)
            {
                case (Keys.Control | Keys.N):
                    this.ucToolBar_AddClick(this);
                    return true;

                case (Keys.Control | Keys.P):
                    this.ucToolBar_PrintClick(this);
                    return true;

                case (Keys.Control | Keys.S):
                    this.ucToolBar_SaveClick(this);
                    return true;

                case (Keys.Control | Keys.T):
                    this.ucToolBar_AddClick(this);
                    return true;

                case (Keys.Shift | Keys.F2):
                    this.ucToolBar_SaveNewClick(this);
                    return true;

                case Keys.F1:
                    this.F11Execute();
                    return true;

                case Keys.F2:
                    this.ucToolBar_SaveClick(this);
                    return true;

                case Keys.F3:
                    this.F3Execute();
                    return true;

                case Keys.F4:
                    this.F4Execute();
                    return true;

                case Keys.F5:
                    this.F5Execute();
                    return true;

                case Keys.F6:
                    this.F9Execute();
                    return true;

                case Keys.F7:
                    this.F7Execute();
                    return true;

                case Keys.F8:
                    this.F8Execute();
                    return true;

                case Keys.F9:
                    this.F9Execute();
                    return true;

                case Keys.F10:
                    this.F10Execute();
                    if (base.ParentForm != null)
                    {
                        base.ParentForm.Close();
                    }
                    return true;

                case Keys.F11:
                    this.F11Execute();
                    return true;

                case Keys.F12:
                    this.F12Execute();
                    return true;

                case Keys.Escape:
                    this.EscapeExecute();
                    return true;

                case (Keys.Control | Keys.W):
                    this.ucToolBar_SaveClick(this);
                    return true;

                case (Keys.Control | Keys.Shift | Keys.S):
                    this.ucToolBar_SaveNewClick(this);
                    return true;

                case (Keys.Control | Keys.Shift | Keys.W):
                    this.ucToolBar_SaveNewClick(this);
                    return true;

                case (Keys.Alt | Keys.D):
                    return true;

                case (Keys.Alt | Keys.X):
                    if (base.ParentForm != null)
                    {
                        base.ParentForm.Close();
                    }
                    return true;
            }
            base.NotSave = true;
            this.Bar.Bar.bbiSaveM.Enabled = true;
            return false;
        }

        public virtual void ProductAdd(object item)
        {
        }

        public virtual void ProductDetail()
        {
        }

        public virtual void ProviderSelected(object item)
        {
        }

        public virtual void ReadDataByID()
        {
        }

        public virtual void ReadFromFile(string name)
        {
        }

        public virtual void ReadLayout(string name)
        {
        }

        protected virtual void Refresh()
        {
        }

        public virtual void RestoreTemp()
        {
        }

        public virtual string Save()
        {
            if (this.Check())
            {
                if (base.Status == Actions.Add)
                {
                    return this.uc_Save();
                }
                if (base.Status == Actions.Update)
                {
                    this.uc_Update();
                }
                else if (base.Status == Actions.Change)
                {
                    this.uc_Change();
                }
            }
            return "";
        }

        public virtual void SaveDataByID()
        {
        }

        public virtual void SaveInterface()
        {
        }

        public virtual void SaveLayout(string name)
        {
        }

        public virtual void SaveTemp()
        {
        }

        public virtual void SaveToFile(string name)
        {
        }

        public virtual void Search()
        {
        }

        public virtual void SelectAll()
        {
        }

        public virtual void SetData(string id)
        {
        }

        public virtual void SetInterface()
        {
        }

        public virtual string uc_Change()
        {
            return string.Empty;
        }

        public virtual string uc_Delete()
        {
            return string.Empty;
        }

        public virtual string uc_Save()
        {
            return string.Empty;
        }

        public virtual string uc_Update()
        {
            return string.Empty;
        }

        private void ucBarB_CopyClick(object sender)
        {
            this.Copy();
        }

        private void ucBarB_HelpClick(object sender)
        {
            Process.Start("http://www.tanvietpro.com/huong-dan-su-dung-phan-mem-quan-ly-doanh-nghiep-Smart.erp.htm");
        }

        private void ucBarB_ReadLayoutClick(object sender)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "Xml File(*.xml)|*.xml|All File(*.*)|*.*";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                this.ReadLayout(dialog.FileName);
            }
        }

        private void ucBarB_RefreshClick(object sender)
        {
            this.Refresh();
        }

        private void ucBarB_SaveLayoutClick(object sender)
        {
            SaveFileDialog dialog = new SaveFileDialog();
            dialog.Filter = "Xml File(*.xml)|*.xml|All File(*.*)|*.*";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                this.SaveLayout(dialog.FileName);
            }
        }

        private void ucToolBar_AddClick(object sender)
        {
            this.Clear();
            this.Add();
        }

        private void ucToolBar_CancleClick(object sender)
        {
            this.Cancel();
        }

        private void ucToolBar_ClearClick(object sender)
        {
            this.DeleteAll();
        }

        private void ucToolBar_CloseClick(object sender)
        {
            if (base.ParentForm != null)
            {
                base.ParentForm.Close();
            }
        }

        private void ucToolBar_DeleteClick(object sender)
        {
            this.DeleteSelected();
        }

        private void ucToolBar_ExportClick(object sender)
        {
            base.Export();
        }

        private void ucToolBar_HistoryClick(object sender)
        {
            this.History();
        }

        private void ucToolBar_InventoryClick(object sender)
        {
            this.Inventory();
        }

        private void ucToolBar_PrintClick(object sender)
        {
            this.Print();
        }

        private void ucToolBar_ProductDetailClick(object sender)
        {
            this.ProductDetail();
        }

        private void ucToolBar_ReadDataByIDClick(object sender)
        {
            this.ReadDataByID();
        }

        private void ucToolBar_ReadFromFileClick(object sender)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "Xml File(*.xml)|*.xml|All File(*.*)|*.*";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                this.ReadFromFile(dialog.FileName);
            }
        }

        private void ucToolBar_RestoreTempClick(object sender)
        {
            this.RestoreTemp();
        }

        private void ucToolBar_SaveClick(object sender)
        {
            if (this.Bar.Bar.bbiSave.ImageIndex == this.Bar.Bar.bbiSaveNew.ImageIndex)
            {
                if (this.Save() == "OK")
                {
                    this.ucToolBar_AddClick(sender);
                }
            }
            else
            {
                this.Save();
            }
        }

        private void ucToolBar_SaveDataByIDClick(object sender)
        {
            this.SaveDataByID();
        }

        private void ucToolBar_SaveNewClick(object sender)
        {
            if (this.Save() == "OK")
            {
                this.ucToolBar_AddClick(sender);
            }
        }

        private void ucToolBar_SaveTempClick(object sender)
        {
            this.SaveTemp();
        }

        private void ucToolBar_SaveToFileClick(object sender)
        {
            SaveFileDialog dialog = new SaveFileDialog();
            dialog.Filter = "Xml File(*.xml)|*.xml|All File(*.*)|*.*";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                this.SaveToFile(dialog.FileName);
            }
        }

        private void ucToolBar_SearchClick(object sender)
        {
            this.Search();
        }

        private void ucToolBar_SelectAllClick(object sender)
        {
            this.SelectAll();
        }

        public xucBarB Bar
        {
            get
            {
                return this.ucBarB;
            }
        }
    }
}
